//
//  CollectionCellForFirst.m
//  Movie
//
//  Created by dllo on 16/3/24.
//  Copyright © 2016年 HY. All rights reserved.
//

#import "CollectionCellForFirst.h"
#import "MovieModel.h"
#import <UIImageView+WebCache.h>

@implementation CollectionCellForFirst

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        self.labForTitle = [[UILabel alloc] init];
        self.img = [[UIImageView alloc] init];
        self.labForFX = [[UILabel alloc] init];
        self.labForPF = [[UILabel alloc] init];
        self.labelForHUA = [[UILabel alloc] init];
        self.str = [[NSString alloc] init];
        
        self.imgForFX = [[UIImageView alloc] init];
        self.imgForPF = [[UIImageView alloc] init];
        
        [self.contentView addSubview:self.labelForHUA];
        [self.contentView addSubview:self.labForTitle];
        [self.contentView addSubview:self.img];
        [self.contentView addSubview:self.labForPF];
        [self.contentView addSubview:self.labForFX];
        [self.contentView addSubview:self.imgForPF];
        [self.contentView addSubview:self.imgForFX];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
    
    self.labForTitle.frame = CGRectMake(10, 10, self.contentView.frame.size.width - 20, 50);
    self.labForTitle.numberOfLines = 0;
    
    self.img.frame = CGRectMake(15, 60, self.contentView.frame.size.width - 30, self.contentView.frame.size.height - 10 - 30 - 30 - 20);
    self.img.layer.cornerRadius = 3;
    self.img.layer.masksToBounds = YES;
    
    self.imgForPF.frame = CGRectMake(20, self.contentView.frame.size.height - 25, 20, 20);
    self.imgForPF.image = [UIImage imageNamed:@"PF"];
    self.labForPF.frame = CGRectMake(47, self.contentView.frame.size.height - 30, (self.img.frame.size.width - 60) / 2 - 30, 30);
    
    self.imgForFX.frame = CGRectMake((self.img.frame.size.width - 60) / 2 + 10, self.contentView.frame.size.height - 25, 22, 22);
    self.imgForFX.image = [UIImage imageNamed:@"FX"];
    self.labForFX.frame = CGRectMake((self.img.frame.size.width - 60) / 2 + 40, self.contentView.frame.size.height - 30, (self.img.frame.size.width - 60) / 2, 30);
    
    self.labelForHUA.frame = CGRectMake(0, self.contentView.frame.size.height , self.contentView.frame.size.width , 8);
    self.labelForHUA.lineBreakMode = NSLineBreakByCharWrapping;
    self.labelForHUA.text = @"✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿✿";
    
    self.labForTitle.textColor = [UIColor whiteColor];
    self.labForPF.textColor = [UIColor redColor];
    self.labForFX.textColor = [UIColor redColor];
    self.labelForHUA.textColor = [UIColor colorWithRed:60 / 255.f green:170 / 255.f blue:255 / 255.f alpha:1];
    
    self.labelForHUA.font = [UIFont boldSystemFontOfSize:10];
    self.labForTitle.font = [UIFont boldSystemFontOfSize:16];
    self.labForPF.font = [UIFont systemFontOfSize:15];
    self.labForFX.font = [UIFont systemFontOfSize:14];
}



- (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
    
    return layoutAttributes;
}


- (void)layoutSubviews{
    
    [super layoutSubviews];
}


- (void)passModel:(MovieModel *)model{
    
    [self.img sd_setImageWithURL:[NSURL URLWithString:model.coverForDetail]  placeholderImage:[UIImage imageNamed:@"zwt"]];
    
    self.labForTitle.text = model.title;
    self.labForPF.text = [NSString stringWithFormat:@"评分: %@",model.rating];
    self.labForFX.text = model.share_num;
}



@end
